package com.fr.base.file;

import com.fr.base.FRContext;
import com.fr.base.Style;
import com.fr.base.XMLFileManager;
import com.fr.base.core.util.ListMap;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.ReportWebAttr;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.io.xml.SynchronizedVersion;
import com.fr.report.parameter.Parameter;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ConfigManager extends XMLFileManager
{
  private String serverCharset = null;
  private Level serverLogLevel = Level.WARNING;
  private int concurrency = 100;
  private int concurrencyOnce = 10;
  private ReportWebAttr reportWebAttr = new ReportWebAttr();
  private Parameter[] globeParameters = new Parameter[0];
  private Map styleMap = new ListMap();
  private boolean popupFlashPrintSetting = true;
  private boolean popupPdfPrintSetting = true;
  private String ServletMapping = "ReportServer";
  private boolean supportGzip = false;
  private int serverLanguage = 0;
  private String resultSaverClassName = null;

  public String fileName()
  {
    return "config.xml";
  }

  public String getServerCharset()
  {
    if (this.serverCharset == null)
      this.serverCharset = getDefaultBrowserCharset();
    return this.serverCharset;
  }

  public void setServerCharset(String paramString)
  {
    this.serverCharset = paramString;
  }

  private String getDefaultBrowserCharset()
  {
    if (Locale.SIMPLIFIED_CHINESE.equals(FRContext.getLocale()))
      return "GBK";
    if (Locale.TRADITIONAL_CHINESE.equals(FRContext.getLocale()))
      return "BIG5";
    if (Locale.JAPANESE.equals(FRContext.getLocale()))
      return "EUC_JP";
    if (Locale.KOREAN.equals(FRContext.getLocale()))
      return "EUC_KR";
    return "UTF-8";
  }

  public Level getServerLogLevel()
  {
    return this.serverLogLevel;
  }

  public void setServerLogLevel(Level paramLevel)
  {
    this.serverLogLevel = paramLevel;
    FRContext.getLogger().setLevel(paramLevel);
  }

  public int getConcurrency()
  {
    return this.concurrency;
  }

  public void setConcurrency(int paramInt)
  {
    this.concurrency = Math.max(paramInt, 0);
  }

  public int getConcurrencyOnce()
  {
    return this.concurrencyOnce;
  }

  public void setConcurrencyOnce(int paramInt)
  {
    this.concurrencyOnce = Math.max(paramInt, 1);
  }

  public boolean isPopupFlashPrintSetting()
  {
    return this.popupFlashPrintSetting;
  }

  public boolean isPopupPdfPrintSetting()
  {
    return this.popupPdfPrintSetting;
  }

  public void setPopupFlashPrintSetting(boolean paramBoolean)
  {
    this.popupFlashPrintSetting = paramBoolean;
  }

  public void setPopupPdfPrintSetting(boolean paramBoolean)
  {
    this.popupPdfPrintSetting = paramBoolean;
  }

  public void setSupportGzip(boolean paramBoolean)
  {
    this.supportGzip = paramBoolean;
  }

  public boolean isSupportGzip()
  {
    return this.supportGzip;
  }

  public void setServerLanguage(int paramInt)
  {
    this.serverLanguage = paramInt;
  }

  public int getServerLanguage()
  {
    return this.serverLanguage;
  }

  public boolean hasStyle()
  {
    return this.styleMap.isEmpty();
  }

  public Iterator getStyleNameIterator()
  {
    return this.styleMap.keySet().iterator();
  }

  public Style getStyle(String paramString)
  {
    return ((Style)this.styleMap.get(paramString));
  }

  public void putStyle(String paramString, Style paramStyle)
  {
    if (paramStyle == null)
      this.styleMap.remove(paramString);
    this.styleMap.put(paramString, paramStyle);
  }

  public void removeStyle(String paramString)
  {
    this.styleMap.remove(paramString);
  }

  public void clearAllStyle()
  {
    this.styleMap.clear();
  }

  public String getResultSaverClassName()
  {
    return this.resultSaverClassName;
  }

  public void setResultSaverClassName(String paramString)
  {
    this.resultSaverClassName = paramString;
  }

  public String[] getImportedCss()
  {
    HashSet localHashSet = new HashSet();
    if (this.reportWebAttr != null)
    {
      int i = 0;
      int j = this.reportWebAttr.getCSSImportCount();
      while (i < j)
      {
        localHashSet.add(this.reportWebAttr.getCSSImport(i));
        ++i;
      }
    }
    return ((String[])localHashSet.toArray(new String[localHashSet.size()]));
  }

  public String[] getWriteImportedCss()
  {
    HashSet localHashSet = new HashSet();
    if (this.reportWebAttr != null)
    {
      int i = 0;
      int j = this.reportWebAttr.getWriteCSSImportCount();
      while (i < j)
      {
        localHashSet.add(this.reportWebAttr.getWriteCSSImport(i));
        ++i;
      }
    }
    return ((String[])localHashSet.toArray(new String[localHashSet.size()]));
  }

  public String[] getWidgetImportedCss()
  {
    HashSet localHashSet = new HashSet();
    if (this.reportWebAttr != null)
    {
      int i = 0;
      int j = this.reportWebAttr.getWidgetCSSImportCount();
      while (i < j)
      {
        localHashSet.add(this.reportWebAttr.getWidgetCSSImport(i));
        ++i;
      }
    }
    return ((String[])localHashSet.toArray(new String[localHashSet.size()]));
  }

  public String[] getImportedJs()
  {
    HashSet localHashSet = new HashSet();
    if (this.reportWebAttr != null)
    {
      int i = 0;
      int j = this.reportWebAttr.getJSImportCount();
      while (i < j)
      {
        localHashSet.add(this.reportWebAttr.getJSImport(i));
        ++i;
      }
    }
    return ((String[])localHashSet.toArray(new String[localHashSet.size()]));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    String str1;
    if (paramXMLableReader.isChildNode())
    {
      Object localObject;
      String str2 = paramXMLableReader.getTagName();
      if (str2.equals("XMLVersion"))
      {
        if ((str1 = paramXMLableReader.getElementValue()) != null)
        {
          localObject = SynchronizedVersion.getSynchronizedVersion(Thread.currentThread());
          ((SynchronizedVersion)localObject).setXmlVersionByString(str1);
        }
      }
      else if ("Write".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("serverCharacterEncoding")) != null)
          setServerCharset(str1);
      }
      else if ("SM".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("concurrency")) != null)
          setConcurrency(Integer.parseInt(str1));
        if ((str1 = paramXMLableReader.getAttr("concurrencyOnce")) != null)
          setConcurrencyOnce(Integer.parseInt(str1));
      }
      else if ("GZip".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("run")) != null)
          setSupportGzip(Boolean.valueOf(str1).booleanValue());
      }
      else if ("ServletMapping".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("pattern")) != null)
          setServletMapping(str1);
      }
      else if (("Parameters".equals(str2)) || ("Global_Parameters".equals(str2)))
      {
        this.globeParameters = ReportXMLUtils.readParameters(paramXMLableReader);
      }
      else if (str2.equals("ReportWebAttr"))
      {
        paramXMLableReader.readXMLObject(this.reportWebAttr);
      }
      else if (("ServerLogLevel".equals(str2)) || ("SetServerLogLevel".equals(str2)))
      {
        if ((str1 = paramXMLableReader.getElementValue()) != null)
          try
          {
            localObject = Level.parse(str1);
            setServerLogLevel((Level)localObject);
          }
          catch (IllegalArgumentException localIllegalArgumentException)
          {
          }
      }
      else if (str2.equals("Styles"))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final ConfigManager this$0;

          public void readXML()
          {
            if (paramXMLableReader.isAttr())
              ConfigManager.access$000(this.this$0).clear();
            if (paramXMLableReader.isChildNode())
            {
              String str2 = paramXMLableReader.getTagName();
              if ("SAttr".equals(str2))
              {
                String str1;
                Object localObject = "";
                if ((str1 = paramXMLableReader.getAttr("name")) != null)
                  localObject = str1;
                paramXMLableReader.readXMLObject(new ConfigManager.2(this, localObject));
              }
            }
          }

          static ConfigManager access$100(1 param1)
          {
            return param1.this$0;
          }
        });
      }
      else if (str2.equals("FlashPrint"))
      {
        if ((str1 = paramXMLableReader.getAttr("popupFlashPrintSetting")) != null)
          setPopupFlashPrintSetting(Boolean.valueOf(str1).booleanValue());
      }
      else if (str2.equals("PdfPrint"))
      {
        if ((str1 = paramXMLableReader.getAttr("popupPdfPrintSetting")) != null)
          setPopupPdfPrintSetting(Boolean.valueOf(str1).booleanValue());
      }
    }
    else if (paramXMLableReader.isAttr())
    {
      if ((str1 = paramXMLableReader.getAttr("language")) != null)
        setServerLanguage(Integer.parseInt(str1));
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("ReportServerParameter").attr("language", getServerLanguage());
    if (this.serverLogLevel != null)
    {
      paramXMLPrintWriter.startTAG("ServerLogLevel");
      paramXMLPrintWriter.textNode(String.valueOf(getServerLogLevel()));
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.startTAG("Write").attr("serverCharacterEncoding", getServerCharset());
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("GZip").attr("run", isSupportGzip()).end();
    paramXMLPrintWriter.startTAG("ServletMapping").attr("pattern", getServletMapping()).end();
    paramXMLPrintWriter.startTAG("SM").attr("concurrency", this.concurrency).attr("concurrencyOnce", this.concurrencyOnce).end();
    paramXMLPrintWriter.startTAG("ReportWebAttr");
    this.reportWebAttr.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
    ReportXMLUtils.writeParameters(paramXMLPrintWriter, this.globeParameters);
    paramXMLPrintWriter.startTAG("Styles");
    Iterator localIterator = getStyleNameIterator();
    while (true)
    {
      String str;
      Style localStyle;
      do
      {
        if (!(localIterator.hasNext()))
          break label232;
        str = (String)localIterator.next();
        localStyle = getStyle(str);
      }
      while (localStyle == null);
      paramXMLPrintWriter.startTAG("SAttr").attr("name", str);
      ReportXMLUtils.writeStyle(paramXMLPrintWriter, localStyle);
      paramXMLPrintWriter.end();
    }
    label232: paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("FlashPrint").attr("popupFlashPrintSetting", isPopupFlashPrintSetting()).end();
    paramXMLPrintWriter.startTAG("PdfPrint").attr("popupPdfPrintSetting", isPopupPdfPrintSetting()).end();
    paramXMLPrintWriter.end();
  }

  public ReportWebAttr getReportWebAttr()
  {
    return this.reportWebAttr;
  }

  public void setReportWebAttr(ReportWebAttr paramReportWebAttr)
  {
    this.reportWebAttr = paramReportWebAttr;
  }

  public Parameter[] getGlobal_Parameters()
  {
    return this.globeParameters;
  }

  public void setGlobal_Parameters(Parameter[] paramArrayOfParameter)
  {
    this.globeParameters = paramArrayOfParameter;
  }

  public String getServletMapping()
  {
    return this.ServletMapping;
  }

  public void setServletMapping(String paramString)
  {
    this.ServletMapping = paramString;
  }

  static Map access$000(ConfigManager paramConfigManager)
  {
    return paramConfigManager.styleMap;
  }
}